<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Watch 选项 监控数据</title>
  <script src="../assets/js/vue.js"></script>
</head>

<body>
  <h1>Watch 选项 监控数据</h1>
  <hr>
  <div id="app">
    <p>今日温度:{{wendu}}°</p>
    <p>穿衣建议:{{chuanyi}}</p>
    <p>
      <button @click="shenggao">升高温度</button>
      <button @click="jiangdi">降低温度</button>
    </p>
  </div>
  <script type="text/javascript">
    var chuanyiarray=['T恤短袖','夹克长裙','棉衣羽绒服']
    var app = new Vue({
      el: '#app',
      data: {
        wendu: 14,
        chuanyi:'夹克长裙'
      },
      methods:{
        shenggao:function(){
          this.wendu+=5;
        },
        jiangdi: function () {
          this.wendu -= 5;
        }
      },
      watch:{
        wendu:function(newVal,oldVal){
          if (newVal>=26) {
            this.chuanyi=chuanyiarray[0];
          }else if(newVal < 26 && newVal>0){
            this.chuanyi= chuanyiarray[1];
          }
          else{
            this.chuanyi= chuanyiarray[2];
          }
        }
      }
    })
  </script>
</body>

</html>